package cn.gcjxsc.repository.salesaman;

import cn.gcjxsc.entity.salesman.IntegralRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface IntegralRecordRepository extends JpaRepository<IntegralRecord, Integer>, JpaSpecificationExecutor<IntegralRecord> {

    @Query("select new IntegralRecord(sum(o.amount), o.storeId) from IntegralRecord o where o.source=:source and o.memberId=:memberId group by o.storeId")
    List<IntegralRecord> sumBySourceAndMemberId(@Param("source") String sourceId, @Param("memberId") Integer memberId);
}
